package front

import (
	"github.com/gin-gonic/gin"
	"net/http"
	"qihuang/protocol"
	"qihuang/service/front"
	"strconv"
)

type Hospitals struct {
}

//医院列表
func (Hospitals) GetListByCity(c *gin.Context) {
	resp := &protocol.Resp{Status: 0, Msg: "获取成功！", Data: ""}
	city := c.DefaultQuery("city", "")
	page, err := strconv.Atoi(c.DefaultQuery("page", "1"))
	if city == "" {
		resp.Status = 1
		resp.Msg = "参数错误"
		c.JSON(http.StatusOK, resp)
		return
	}
	if err != nil {
		resp.Status = 1
		resp.Msg = "参数错误"
		c.JSON(http.StatusOK, resp)
		return
	}
	hospitalServ := front.Hospitals{}
	//fields := []string{"id", "author_id", "title", "content", "year", "region", "starring", "show_time", "director",
	//	"img_path", "modify_time", "status","create_time"}
	//resp = movieServ.GetListForEs(page, pageSize, fields)
	resp = hospitalServ.GetListByCityForMysql(city, page)
	//if resp.Status == -999 {
	//	resp = movieServ.GetListForMysql(page, pageSize, fields)
	//}
	c.JSON(http.StatusOK, resp)
}

//医院列表
func (Hospitals) GetList(c *gin.Context) {
	resp := &protocol.Resp{Status: 0, Msg: "", Data: ""}
	page, err := strconv.Atoi(c.DefaultQuery("page", "1"))
	if err != nil {
		resp.Status = 1
		resp.Msg = "参数错误"
		c.JSON(http.StatusOK, resp)
		return
	}
	pageSize, err := strconv.Atoi(c.DefaultQuery("page_size", "20"))
	if err != nil {
		resp.Status = 1
		resp.Msg = "参数错误"
		c.JSON(http.StatusOK, resp)
		return
	}
	hospitalServ := front.Hospitals{}
	//fields := []string{"id", "author_id", "title", "content", "year", "region", "starring", "show_time", "director",
	//	"img_path", "modify_time", "status","create_time"}
	//resp = movieServ.GetListForEs(page, pageSize, fields)
	resp = hospitalServ.GetListForMysql(page, pageSize)
	//if resp.Status == -999 {
	//	resp = movieServ.GetListForMysql(page, pageSize, fields)
	//}
	c.JSON(http.StatusOK, resp)
}

//医院详情
func (Hospitals) Show(c *gin.Context) {
	resp := &protocol.Resp{Status: 1, Msg: "", Data: ""}
	id, err := strconv.Atoi(c.Param("id"))
	hospitalServ := front.Hospitals{}
	if err != nil || id <= 0 {
		resp.Status = 1
		resp.Msg = "参数错误"
		c.JSON(http.StatusOK, resp)
		return
	}
	resp = hospitalServ.GetHospitalDetail(id)
	c.JSON(http.StatusOK, resp)
}

////文章类型
//func (Movies) GetCategories(c *gin.Context) {
//	resp := &protocol.Resp{Status: 0, Msg: "", Data: ""}
//	articleServ := front.Articles{}
//	resp = articleServ.GetArticleCate()
//	c.JSON(http.StatusOK, resp)
//}
